package com.eboss2.sbs.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.eboss2.sbs.R;
import com.eboss2.sbs.model.GoodAttrsQb;
import com.eboss2.sbs.util.ImageLoader;
import com.mytools.tool.utils.StringUtils;

import java.util.ArrayList;
import java.util.List;


/**
 * 主页面中GridView的适配器
 * 
 * @author hanj
 */

public class AdapterGoodsAttrList extends BaseAdapter {

    private Context context;
    private List<GoodAttrsQb> goodAttrsQbs = new ArrayList<GoodAttrsQb>();

    public AdapterGoodsAttrList(Context context, List<GoodAttrsQb> goodAttrsQbs) {
        this.context = context;
        this.goodAttrsQbs = goodAttrsQbs;
    }

    @Override
    public int getCount() {
        return goodAttrsQbs == null ? 0 : goodAttrsQbs.size();
    }

    @Override
    public Object getItem(int position) {
        return goodAttrsQbs.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.listitem_goods_attr_list, null);
            holder.tv_name = convertView.findViewById(R.id.tv_name);
            holder.tv_value = convertView.findViewById(R.id.tv_value);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        GoodAttrsQb goodAttrsQb = goodAttrsQbs.get(position);

        holder.tv_name.setText(StringUtils.isBlank(goodAttrsQb.getGoodsAttrsName()) ? "" : goodAttrsQb.getGoodsAttrsName());
        holder.tv_value.setText(StringUtils.isBlank(goodAttrsQb.getGoodsAttrsValue()) ? "" : goodAttrsQb.getGoodsAttrsValue());


        return convertView;
    }

    private class ViewHolder {

       TextView tv_name;
       TextView tv_value;

    }

}
